import axios from "axios"
import { constants } from ".";


// 同步更新reducer中的state
export const updateDetailData = (data) => ({
  type: constants.UPDATE_DETAIL_DATE,
  payload: data
})

// 异步获取数据
export const getDetailData = (params) => {
  return (dispatch) => {
    axios.get(`/api/detail.json?id=${params.id}`)
      .then(response => {
        const { data: { data } } = response;
        dispatch(updateDetailData(data))
      },
      error => { console.log('get Detail data error.') })
  }
}
